package com.example.user.controller;


import com.alibaba.fastjson.JSONObject;
import com.example.commons.filter.RequestFilter;
import com.example.commons.response.ResponseResult;
import com.example.commons.response.ResultCode;
import com.example.commons.util.UserUtil;
import com.example.commons.vo.UserVo;
import com.example.user.service.LoginService;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    LoginService loginService;

    @PostMapping("/login")
    @Trace
    public ResponseResult login(RequestFilter request) throws InterruptedException {
        JSONObject req = request.getRequestBodyJson();
        //todo 此处应对请求体做加密解密处理
        String[] login = loginService.login(req.getString("username"), req.getString("password"));
        JSONObject retData = new JSONObject();
        retData.put("token", login[0]);
        retData.put("uid", login[1]);
        return new ResponseResult(ResultCode.SUCCESS, "登录成功", retData);
    }
}
